import javax.swing.text.AbstractDocument;
import javax.swing.text.BoxView;
import javax.swing.text.ComponentView;
import javax.swing.text.Element;
import javax.swing.text.IconView;
import javax.swing.text.LabelView;
import javax.swing.text.ParagraphView;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;

/**
 * This Class creates a new View, governing how the contents of the element
 * should be displayed (In Tasky's context, this is to ensure Word-wrapping
 * for JTextPane)
 * 
 * @author Keith Lim Yong Ming A0097846J
 *
 */

public class ColumnWrapper implements ViewFactory {

	public View create(Element receivedElement) {

		String typeOfElement = receivedElement.getName();

		/* This is the overwritten Class */
		LabelView overWrittenLabelView = new TextPaneLabelViewWrap(receivedElement);

		if (typeOfElement != null) {
			if (typeOfElement.equals(AbstractDocument.ContentElementName)) {
				return overWrittenLabelView;
			} else if (typeOfElement.equals(AbstractDocument.ParagraphElementName)) {
				return new ParagraphView(receivedElement);
			} else if (typeOfElement.equals(AbstractDocument.SectionElementName)) {
				return new BoxView(receivedElement, View.Y_AXIS);
			} else if (typeOfElement.equals(StyleConstants.ComponentElementName)) {
				return new ComponentView(receivedElement);
			} else if (typeOfElement.equals(StyleConstants.IconElementName)) {
				return new IconView(receivedElement);
			}
		}

		// default to text display
		return new LabelView(receivedElement);
	}
}